<template>
    <view class="goods-item" @tap="active(goods)" :class="acid.goodsId == goods.goodsId ? 'ac' : '' ">
        <view class="goods-img">
            <image :src="goods.avatar" mode="aspectFill"></image>
        </view>
        <view class="goods-info">
            <view class="goods-name">
                <text>{{ goods.goodsName }}</text>
                <u-icon v-if="hasDelBtn" @click="delGood(goods)" name="close-circle" color="orange"></u-icon>
            </view>
            <view class="price-box">
                <view class="goods-price">¥
                    <text>{{ goods.price }}</text>
                    元/{{goods.unit}}
                </view>
                <view class="saleCount" >已团 {{goods.count_t}} {{goods.unit}}</view>
            </view>
            <view class="goods-quantity">
                <u-number-box  class="countBox" disabled-input :index="goods.goodsId" :min="0" :value="goods.num" @change="changeNum"></u-number-box>
                <view class="add-cart"  @click="addToCart(goods.goodsId)">加入购物车</view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    props: {
        goods: {
            type: Object,
            required: true
        },
		acid:{
			type: Object,
			required: true
		},
        hasDelBtn: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {}
    },
    methods: {
       
        // 数量改变
        changeNum({value,index}){
            if(value==0 && this.hasDelBtn){
                // 删除商品
                this.$emit('delGoods',index)
            }else{
                // 改变商品数量
                this.$emit('changeNum',{value,index})
            }
        },
        // 加入购物车
        addToCart(id){
            this.$emit('addCart',{index:id})
        },
        // 删除商品
        delGood(good){
            this.$emit('delGoods',good)
        },
		
		//  触摸商品item
		active(v){
			this.$emit('taps',v)
		},
		
    }
}
</script>

<style lang="scss" scoped>
.goods-item {
    display: flex;
    align-items: center;
    height: 240rpx;
    padding: 20rpx;
    border: 1rpx solid #ffffff;
    background-color: #fff;
    margin-top:20rpx;
    box-sizing: border-box;
	border-radius: 10rpx;
}
	.ac{border: 1rpx solid orangered;}	

.goods-img {
    width: 170rpx;
    height: 200rpx;
    border-radius: 20rpx;
    overflow: hidden;
    margin-right: 20rpx;

    image {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

.goods-info {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.goods-name {
    font-size: 32rpx;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.price-box {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .goods-price {
        font-size: 26rpx;

        text {
            font-size: 16px;
            color: #f00;
        }
    }
    .saleCount {
        font-size: 14px;
        color: #07c061;
    }
}


.goods-quantity {
    display: flex;
    align-items: center;
    justify-content: space-between;

    ::v-deep .u-icon-minus {
        background-color: transparent;
        border: 1px solid rgb(7, 193, 69);
    }
}

.quantity-btn {
    width: 60rpx;
    height: 60rpx;
    line-height: 60rpx;
    text-align: center;
    border: 1rpx solid #e5e5e5;
    border-radius: 50%;
    margin-right: 20rpx;
}

.quantity-num {
    width: 80rpx;
    text-align: center;
}

.add-cart {
    width: 200rpx;
    height: 60rpx;
    line-height: 60rpx;
    text-align: center;
    background-color:#07c061;;
    color: #fff;
    border-radius: 30rpx;
}
</style>
